<?php

/**
 * 这是一个表 "activity_detail" 的模型类。
 *
 * 表 'activity_detail' 有以下字段:
 * @property integer $id
 * @property integer $is_float
 * @property integer $activity_id
 * @property integer $crowd_id
 * @property string $remark
 * @property string $begins
 * @property string $start
 * @property string $end
 * @property integer $astrict
 * @property integer $is_state
 * @property string $clander_start
 * @property string $clander_end
 * @property string $invitation_code
 *
 * 以下是表的关联关系:
 * @property Activity $activity
 * @property LineDetail[] $lineDetails
 */
class ActivityDetail extends CActiveRecord
{
	/**
	 * @return string 表名
	 */
	public function tableName()
	{
		return 'activity_detail';
	}

	/**
	 * @return array 表字段验证规则的数组。
	 */
	public function rules()
	{
		return array(
                        array('is_float,activity_id,crowd_id,start,end,astrict,begins', 'required'),
			array('is_float, activity_id, crowd_id, astrict, is_state', 'numerical', 'integerOnly'=>true),
			array('remark, start, end ,begins, clander_start, clander_end, invitation_code', 'safe'),
			// 以下规则用于验证查询函数，如果不做查询可注释此行。
			array('id, is_float, activity_id, crowd_id, remark, start,begins, end, astrict, is_state, clander_start, clander_end, invitation_code', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array 关联关系。
	 */
	public function relations()
	{
		return array(
			'activity' => array(self::BELONGS_TO, 'Activity', 'activity_id'),
			'lineDetails' => array(self::HAS_MANY, 'LineDetail', 'ad_id'),
                        'crowd' => array(self::BELONGS_TO, 'Crowd', 'crowd_id'),
		);
	}

	/**
	 * @return array 自定义字段显示文本标签 (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '序号',
			'is_float' => '场馆状态',
			'activity_id' => '活动名称',
			'crowd_id' => '人群属性',
			'remark' => '简介',
                        'begins' => '日历时间',
			'start' => '报名开始时间',
			'end' => '报名结束时间',
			'astrict' => '限制人数',
			'is_state' => '状态',
                        'clander_start' => '活动开始时间',
                        'clander_end' => '活动结束时间',
                        'invitation_code' => '邀请码',
		);
	}

	/**
	 * 自定义查询函数
	 * @return CActiveDataProvider 一个包含分页排序查询数据
	 */
	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('is_float',$this->is_float);
		$criteria->compare('activity_id',$this->activity_id);
		$criteria->compare('crowd_id',$this->crowd_id);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('start',$this->start,true);
                $criteria->compare('begins',$this->begins,true);
		$criteria->compare('end',$this->end,true);
		$criteria->compare('astrict',$this->astrict);
		$criteria->compare('is_state',$this->is_state);
                $criteria->compare('clander_start',$this->clander_start,true);
                $criteria->compare('clander_end',$this->clander_end,true);
                $criteria->compare('invitation_code',$this->invitation_code,true);
		$criteria->order='id desc';//排序字段

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
                'pageSize'=>Yii::app()->params['pagesize'],//配置文件中设置过分页条数
            ),
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return ActivityDetail the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
